package com.xxx.meter.ui.meter.reading.selection2;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.xxx.meter.R;
import com.xxx.meter.base.BaseActivity;
import com.xxx.meter.base.BaseDialog;
import com.xxx.meter.model.utils.ButtonUtil;
import com.xxx.meter.model.utils.ToastUtil;
import com.xxx.meter.ui.main.custom.MyLayoutManager;
import com.xxx.meter.ui.meter.reading.selection.MeterReadingSelectionAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class MeterReadingSelectionWindow2 extends BaseDialog {

    @BindView(R.id.window_patrol_selection_edit)
    EditText mEditView;

    private Callback callback;
    private double value;

    public static MeterReadingSelectionWindow2 getInstance(BaseActivity activity, double value, Callback callback) {
        return new MeterReadingSelectionWindow2(activity, value, callback);
    }

    private MeterReadingSelectionWindow2(Context context, double value, Callback callback) {
        super(context, 0.95, false);
        this.value = value;
        this.callback = callback;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.window_patrol_selection2;
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void initData() {
//        mEditView.setText(value + "");
    }

    @OnClick({R.id.window_patrol_selection_finish, R.id.window_patrol_selection_btn})
    public void OnClick(View view) {
        if (ButtonUtil.isFastClick()) return;
        switch (view.getId()) {
            case R.id.window_patrol_selection_finish:
                dismiss();
                break;
            case R.id.window_patrol_selection_btn:
                try {
                    value = Double.parseDouble(mEditView.getText().toString());
                    if (value > 10000) {
                        ToastUtil.showToast("请确认数值是否输入正确");
                        return;
                    }
                } catch (Exception e) {
                    ToastUtil.showToast("请确认数值是否输入正确");
                    return;
                }
                if (callback != null) callback.callback(value);
                break;
        }
    }

    public interface Callback {
        void callback(double value);
    }
}
